using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;//For menu commands

using System.Drawing;
//using System.Drawing.Printing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Camalon.Drawing;


namespace Camalon.Drawing.Design
{
	/// <summary>
	/// Summary description for ShapeComponentTray.
	/// </summary>
    [ToolboxItem(false)]
    public class ShapeComponentTray : System.Windows.Forms.UserControl
	{
		protected internal event EventHandler SelectedIndexChanged;
		protected internal event EventHandler CloseClick;
		ShapeContainerRootDesignerBase	_rootDesigner;
		MenuCommandsHelper	_mcs;

		private Camalon.Drawing.Design.HeaderControl headerControl1;
		private System.Windows.Forms.Panel trayPanel;

		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ShapeComponentTray()
		{
			SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);

			InitializeComponent();
			
			this.headerControl1.CloseClick+=new EventHandler(HeaderControl_CloseClick);
			this.headerControl1.SelectedIndexChanged+=new ValueChangeEventHandler(HeaderControl_SelectedIndexChanged);

		}


		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
//			// We ( the ExtendedDesignerView ) and the ComponentDocumentDesigner
//			// both hang on to the CompositionUI.
//			// When the ExtendedDesignerView is disposed, it will also dispose
//			// its of its child controls.
//			// However, the DocumentComponentDesigner owns the CompositionUI
//			// and will dispose it as well.
//			// So we remove the component tray from our Children control collection.
			if (_trayControl!= null && this.trayPanel != null && this.trayPanel.Controls.Contains(_trayControl))
				this.trayPanel.Controls.Remove(_trayControl);

			_trayControl = null;

			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}


		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.trayPanel = new System.Windows.Forms.Panel();
            this.headerControl1 = new Camalon.Drawing.Design.HeaderControl();
            this.SuspendLayout();
            // 
            // trayPanel
            // 
            this.trayPanel.AllowDrop = true;
            this.trayPanel.AutoScroll = true;
            this.trayPanel.BackColor = System.Drawing.SystemColors.Info;
            this.trayPanel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.trayPanel.Location = new System.Drawing.Point(0, 20);
            this.trayPanel.Name = "trayPanel";
            this.trayPanel.Size = new System.Drawing.Size(552, 144);
            this.trayPanel.TabIndex = 0;
            // 
            // headerControl1
            // 
            this.headerControl1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(245)))));
            this.headerControl1.Dock = System.Windows.Forms.DockStyle.Top;
            this.headerControl1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.headerControl1.Location = new System.Drawing.Point(0, 0);
            this.headerControl1.Name = "headerControl1";
            this.headerControl1.Size = new System.Drawing.Size(552, 20);
            this.headerControl1.TabIndex = 1;
            this.headerControl1.TabPages = new string[0];
            // 
            // ShapeComponentTray
            // 
            this.BackColor = System.Drawing.SystemColors.Info;
            this.Controls.Add(this.trayPanel);
            this.Controls.Add(this.headerControl1);
            this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "ShapeComponentTray";
            this.Size = new System.Drawing.Size(552, 164);
            this.ResumeLayout(false);

		}
		#endregion


		private void HeaderControl_CloseClick(object sender, EventArgs e)
		{
			if( this.CloseClick != null) this.CloseClick( sender, e);

		}

		private void HeaderControl_SelectedIndexChanged(object sender, ValueChangeEventArgs e)
		{
			if( this.SelectedIndexChanged!= null) this.SelectedIndexChanged( sender, e);
		}

		ComponentTray _trayControl = null;

		protected internal void AddTrayControl(ComponentTray trayControl)
		{
			try
			{
				if( _trayControl == null && _trayControl != trayControl ) 
				{
					//FileWatcher.WriteLine( "ShapeComponentTray::TrayControl added");
					_trayControl = trayControl;
					_trayControl.Dock = DockStyle.Fill;
					this.trayPanel.Controls.Add( _trayControl );
//					_trayControl.Visible = true;//No need for this
				}

			}
			catch( Exception e )
			{
				FileWatcher.WriteLine( "ShapeComponentTray::AddTrayControl:"+ e.Message);

			}

		}


		protected override void OnRightToLeftChanged(EventArgs e)
		{
			if( _trayControl != null && _trayControl.Visible ) _trayControl.Visible = false;
			base.OnRightToLeftChanged (e);
			if( _trayControl != null) _trayControl.Visible = true;


		}

		protected internal void SetRootDesigner( ShapeContainerRootDesignerBase rootDesigner, MenuCommandsHelper mcs)
		{
			try
			{
				_rootDesigner	= rootDesigner;
				_mcs			= mcs;
				
			}
			catch( Exception exc )
			{
				FileWatcher.WriteLine( "Tray::SetRootDesigner:"+ exc.Message);
			}
		}

		

	}
}
